<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../../css/mui.min.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/html-base.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/public.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/list.css"/>
    <script type="text/javascript" src="../../script/newresize.js"></script>
    <script type="text/javascript" src="../../script/mui.min.js"></script>
    <style type="text/css">
    	body,html{overflow: hidden;}
    	.header{position: absolute;}
    	.lungang-status-0{
			color: #44a6d6;
		}
		.lungang-status-1{
			color: #e88439;
		}
		.lungang-status-2{
			color: #5bc432;
		}
		.lungang-status-3{
			color: #eb535c;
		}
		.container {
		    padding-top: 0;
		}
    </style>
</head>
<body>
	<!-- <header class="header fix-header">
		<a class="mui-action-back mui-icon mui-icon-left-nav"></a>
		<h1 class="mui-title">调整轮岗</h1>
	</header> -->
	<div class="container fankuicontainer">
		<p class="apply-tit">选择轮岗岗位</p>
		<form>
			<ul id="post_list" class="lungcont">
				<!-- <li class="item lungang-status-0"><p>仓储规划岗</p><span class="lunglabel">未进行</span></li>
				<li class="item lungang-status-2"><p>快递配送岗</p><span class="lunglabel">已完成</span></li>
				<li class="item lungang-status-0"><p>客   服   岗</p><span class="lunglabel">未进行</span></li>
				<li class="item lungang-status-2"><p>运输规划岗</p><span class="lunglabel">已完成</span></li> -->
				<li id="undefined" index="0" class="item lungang-status-0 post-cell"></li><li id="undefined" index="1" class="item lungang-status-0 post-cell"></li>
			</ul>
		</form>
		<div id="submitBtn" onclick="onSubmitClick()" class="apply-submit">提交</div>
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/jquery.min.js"></script>
<script type="text/javascript" src="../../script/MD5.js"></script>
<script type="text/javascript" src="../../script/requestTool.js"></script>
<script type="text/javascript" src="../../script/timeStampTool.js"></script>
<script type="text/javascript">
	var companyPostArr = new Array();
	var selectedPost = null;
	apiready = function(){
	    loadPostListData();
	}
	function loadPostListData(){
		var postData = api.pageParam.postData;
		var companyid = postData.companyid;
		var params = {
			companyid : companyid,
			uid : $api.getStorage('cfnetppuid')
		};
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '数据加载中...',
		    text: '',
		    modal: false
		});
		cfnetppPOST(url_newPracticeCompanyDetail, params, true, function(data, status){
			api.hideProgress();
			if (status == 'success') {
				if (data.code == 200) {
					var companyData = data.data.company_list;
					var post_list = companyData.post_list;
					if (post_list != undefined && post_list != null && post_list.constructor == Array && post_list.length > 0) {
						companyPostArr = post_list;
						var htmlString = '';
						for (var i = 0; i < post_list.length; i++) {
							var postData = post_list[i];
							htmlString += postCellHtml(i, postData);
						}
						$('#post_list').html(htmlString);
						setupPostTag();
						setupPostCellClick();
					}
				}
			}
		});
	}
	function onSubmitClick(){
		if (selectedPost == null) {
			api.toast({
			    msg: '请选择要调换的岗位'
			});
			return;
		}
		var oldPostData = api.pageParam.postData;
		var params = {
			uid : $api.getStorage('cfnetppuid'),
			jid : $api.getStorage('cfnetppjid'),
			sfid : oldPostData.sfid,
			practicestatus_id : oldPostData.practicestatus_id,
			before_post_id : oldPostData.post_id,
			after_post_id : selectedPost.postid
		};
		api.showProgress({
		    style: 'default',
		    animationType: 'fade',
		    title: '提交中...',
		    text: '',
		    modal: true
		});
		// console.log(JSON.stringify(params)+'\n'+url_newPracticeTransferPost);
		cfnetppPOST(url_newPracticeTransferPost, params, false, function(data, status){
			api.hideProgress();
			if (status == 'success') {
				if (data.code == 200) {
					api.openFrame({
					    name: 'NewPracticeApplySucceed',
					    url: 'NewPracticeApplySucceed.html',
					    rect: {
					        x: 0,
					        y: 66,
					        w: 'auto',
					        h: api.winHeight - 66
					    },
					    pageParam: {
					        message: '岗位调整信息提交成功<br>等待师傅审核'
					    },
					    bounces: false
					});
					// api.toast({
					//     msg: '提交成功，请等待师傅审核'
					// });
					// setTimeout(function(){
					// 	api.closeWin({
					// 	    name: 'NewPracticeApplyChangePost_win'
					// 	});
					// }, 1000);
				}else{
					api.toast({
					    msg: data.message
					});
				}
			}else{
				api.toast({
				    msg: '网络异常'
				});
			}
		});
	}
	function setupPostTag(){
		var postArr = api.pageParam.postArr;
		for (var i = 0; i < postArr.length; i++) {
			var postData = postArr[i];
			var status = postData.status;
			var tag = '';
			switch(status){
				case 0:
				tag = '未开始';
				break;
				case 1:
				tag = '进行中';
				break;
				case 2:
				tag = '已通过';
				break;
				case 3:
				tag = '未通过';
				break;
			}
			var post_id = postData.post_id;
			var postClass = 'lungang-status-'+status;
			$('#'+post_id).addClass(postClass);
			$('#post_tag'+post_id).text(tag);
		}
	}
	function setupPostCellClick(){
		$(".post-cell").unbind('click');
		$(".post-cell").on("click",function(){
			var index = $(this).attr('index');
			var postData = companyPostArr[parseInt(index)];
			var oldId = api.pageParam.postData.post_id;
			if (postData.postid == oldId) {
				api.toast({
				    msg: '当前岗位无需调换'
				});
				return;
			}
			if ($(this).hasClass('lungang-status-1')) {
				api.toast({
				    msg: '该岗位正在进行中，无法调换'
				});
				return;
			}
			if ($(this).hasClass('lungang-status-2')) {
				api.toast({
				    msg: '该岗位已通过'
				});
				return;
			}
			$(".post-cell").removeClass("active");
			$(this).addClass("active");
			selectedPost = postData;
		})
	}
	function postCellHtml(index, data){
		return '<li id="'+data.postid+'" index="'+index+'" class="item post-cell">'+
					'<p>'+data.post_name+'</p>'+
					'<span id="post_tag'+data.postid+'" class="lunglabel">'+
					'</span>'+
				'</li>';
	}
</script>
</html>